package com.mrx.commons.logback.appender;

import ch.qos.logback.classic.spi.ILoggingEvent;
import com.mrx.commons.logback.collector.OpenObserveLogCollector;
import com.mrx.commons.logback.provider.OpenObserveJsonProvider;
import lombok.Setter;
import net.logstash.logback.appender.LoggingEventAsyncDisruptorAppender;
import net.logstash.logback.encoder.LogstashEncoder;

/**
 * openObserve 日志 appender
 *
 * @author Mr.X
 * @since 2023-12-09 下午 11:01:45
 */
public class XLogBackAppender extends LoggingEventAsyncDisruptorAppender {

    @Setter
    private LogstashEncoder encoder;

    @Override
    public void start() {
        super.start();
        encoder.addProvider(new OpenObserveJsonProvider());
    }

    @Override
    protected void append(ILoggingEvent event) {
        OpenObserveLogCollector.submitToOpenObserve(encoder.encode(event));
    }

}
